define(['../../carrys/jsonList','../../carrys/cityList','../../../../js/lib/other/sweet-alert'],function(jsonList,cityData) {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
    	$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','loan'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','3-3'); 	//显示底部文字
    	
    	//默认值
    	$scope.showMsg = true,$scope.promptMsg='请输入相关条件搜索律师';
    	$scope.showResult = false;
    	var provinceList = new Array();
    	var cityListTemp = new Array();
    	$scope.goodField = "";$scope.provinceName = "";$scope.cityName = "";
    	$scope.goodFieldList = jsonList.caseTypeData;//擅长领域
    	
    	collateData();//整理列表数据
    	
    	//显示省份
    	$scope.provinceData = provinceList;
    	
    	//显示城市
    	$scope.clickCity = function(){
    		var cityList = new Array();
    		var provinceName = ($scope.provinceName).province;
    		for(var i=0;i<cityListTemp.length;i++){
    			if(cityListTemp[i].province == provinceName){
    				var tempData = {'city': cityListTemp[i].city};
    				cityList.push(tempData);
    			}
    		}
    		$scope.cityData = cityList;
    	}
    	
    	//点击开始搜索
    	$scope.startSearch = function(){
    	  if(($scope.goodField == "" || $scope.goodField == null) && ($scope.provinceName == ""  || $scope.provinceName == null) && ($scope.cityName == "" || $scope.cityName == null)){
    			$scope.$emit("promptAlertMsg","搜索信息不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if($scope.provinceName == ""  || $scope.provinceName == null){
    			$scope.$emit("promptAlertMsg","所在省份不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}
    		searchLsList();
    	}
    	
    	//点击联系电话
    	$scope.contactLsFn = function(mobileNo){
    		if(mobileNo != ""){
    			callPhone.callPhone(mobileNo,function(ret){
        			
        		},null);
    		}
    	}
    	
    	
    	//搜索律师
    	function searchLsList(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.advField = "";
        	bizInfo.advProvince = "";
        	bizInfo.advCity = "";
        	if($scope.goodField){
        		bizInfo.advField = 	($scope.goodField).val;
        	}
        	if($scope.provinceName){
        		bizInfo.advProvince = ($scope.provinceName).province;
        	}
        	if($scope.cityName){
        		bizInfo.advCity = ($scope.cityName).city;
        	}
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("queryLawyer",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							if(tempData.body != "[]" && tempData.body != ""){
								$scope.showResult = true;
								$scope.showMsg = false;
								$scope.lsInfoList = JSON.parse(tempData.body);
							}else{
								$scope.showResult = false;
								$scope.showMsg = true;
								$scope.lsInfoList = "";
								$scope.promptMsg='未查询到相关律师';
							}
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
		    				$scope.showResult = false;
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							resultData.loginResultData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.showMsg = true;
								$scope.promptMsg='未查询到相关律师';
								$scope.$emit("loadingChange",false);
								$scope.$emit("promptAlertMsg",data.errorMsg);
				    			$scope.$emit("showCollect",true);
				    			$timeout(function(){
				    				$scope.$emit("showCollect",false);
				    			},transData.promptTime);
							}
		    			}else{
		    				$scope.showResult = false;
		    				$scope.showMsg = true;
		    				$scope.promptMsg='未查询到相关律师';
			    			$scope.$emit("loadingChange",false);
							$scope.$emit("promptAlertMsg","连接超时");
			    			$scope.$emit("showCollect",true);
			    			$timeout(function(){
			    				$scope.$emit("showCollect",false);
			    			},transData.promptTime);
		    			}
		    		});
    	}
    	
    	
    	//整理省市数据
    	function collateData() {
    		cityListTemp = new Array();
			for(var key in cityData.addressDetail){
				var tempData = {"province":key};
				provinceList.push(tempData);
				collateCity(key,cityData.addressDetail[key]);
			}
    	}
		function collateCity(data1,data2) {
			for(var key in data2){
				var tempList = {'province':data1,'city': key};
				cityListTemp.push(tempList);
			}
		}
        $scope.$apply();
    }];
});